import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
// vue跳转相同路径报错

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


const routes = [
  {
    path: '/',
    name: 'Login',
    meta: {
      title: '登录'
    },
    component: () => import('../views/login/Login.vue')
  },
  {
    path: '/main',
    name: 'Main',
    meta: {
      title: '主页'
    },
    component: () => import('../views/Main.vue'),
    children: [
      {
        path: '/home',
        name: 'Home',
        meta: {
          title: '首页',
          keepAlive: true
        },
        component: () => import('../views/home/Home.vue'),
      },

      {
        path: '/system',
        component: () => import('../views/system/index.vue'),
        children: [
          {
            path: 'work',
            meta: {
              title: '工作台'
            },
            component: () => import('../views/system/work.vue')
          },
          {
            path: 'mqttlist',
            meta: {
              title: '设备列表'
            },
            component: () => import('../views/mqttList/mqttlist.vue')
          },
          {
            path: 'applist',
            meta: {
              title: 'app列表'
            },
            component: () => import('../views/appList/applist.vue')
          },

          {
            path: 'firmware',
            meta: {
              title: '固件管理'
            },
            component: () => import('../views/firmware/firmware.vue')
          },

          {
            path: 'user',
            meta: {
              title: '用户管理'
            },
            component: () => import('../views/system/user.vue')
          },
          {
            path: 'auth-role/:userId',
            name: 'AuthRole',
            meta: {
              title: '分配角色'
            },
            component: () => import('../views/system/authRole.vue')
          },
          {
            path: 'role',
            meta: {
              title: '角色管理'
            },
            component: () => import('../views/system/role.vue')
          },
          {
            path: 'auth-user/:roleId',
            name: 'AuthUser',
            meta: {
              title: '分配用户'
            },
            component: () => import('../views/system/authUser.vue')
          },
          {
            path: 'menu',
            meta: {
              title: '菜单管理'
            },
            component: () => import('../views/system/menu.vue')
          },
          {
            path: 'menuApp',
            meta: {
              title: 'App菜单管理'
            },
            component: () => import('../views/system/menuApp.vue')
          },
          {
            path: 'dept',
            meta: {
              title: '部门管理'
            },
            component: () => import('../views/system/dept.vue')
          },
          {
            path: 'post',
            meta: {
              title: '岗位管理'
            },
            component: () => import('../views/system/post.vue')
          },
          {
            path: 'dict',
            meta: {
              title: '字典管理'
            },
            component: () => import('../views/system/dict.vue')
          },
          {
            path: 'dict-data/:dictId(\\d+)',
            meta: { title: '字典数据' },
            component: () => import('@/views/system/data.vue')
          },
          {
            path: 'notice',
            meta: {
              title: '通知公告'
            },
            component: () => import('../views/system/notice.vue')
          },
          {
            path: 'operlog',
            meta: {
              title: '操作日志'
            },
            component: () => import('../views/system/operlog.vue')
          },
          {
            path: 'logininfor',
            meta: {
              title: '登录日志'
            },
            component: () => import('../views/system/logininfor.vue')
          },
          {
            path: 'online',
            meta: {
              title: '在线用户'
            },
            component: () => import('../views/system/online.vue')
          },
          {
            path: 'job',
            meta: {
              title: '定时任务'
            },
            component: () => import('../views/system/job.vue')
          },
          {
            path: 'cpu',
            meta: {
              title: '服务监控'
            },
            component: () => import('../views/system/cpu.vue')
          },
          {
            path: 'cache',
            meta: {
              title: '缓存监控'
            },
            component: () => import('../views/system/cache.vue')
          },
          {
            path: 'gen',
            meta: {
              title: '代码生成'
            },
            component: () => import('../views/system/gen/gen.vue')
          },
          {
            path: 'gen/edittable',
            meta: {
              title: '修改生成配置'
            },
            component: () => import('../views/system/gen/editTable.vue')
          },

          //流程管理
          {
            path: 'flowable/definition',
            meta: {
              title: '流程定义'
            },
            component: () => import('@/views/flowable/definition/index.vue')
          },
          {
            path: 'flowable/definition/model',
            meta: {
              title: '流程设计'
            },
            component: () => import('@/views/flowable/definition/model.vue')
          },
          {
            path: 'flowable/form',
            meta: {
              title: '表单配置'
            },
            component: () => import('@/views/flowable/task/form/index.vue')
          },
          {
            path: 'tool/build/index',  //自定义表单
            meta: {
              title: '表单构建'
            },
            component: () => import('@/views/tool/build/index.vue')
          },
          //任务管理
          {
            path: 'flowable/task/process',
            meta: {
              title: '我的流程'
            },
            component: () => import('@/views/flowable/task/process/index.vue')
          },
          {
            path: 'flowable/task/record/index',
            meta: {
              title: '流程处理'
            },
            component: () => import('@/views/flowable/task/record/index.vue')
          },
          {
            path: 'flowable/task/todo',
            meta: {
              title: '待办任务'
            },
            component: () => import('@/views/flowable/task/todo/index.vue')
          },
          {
            path: 'flowable/task/finished',
            meta: {
              title: '已办任务'
            },
            component: () => import('@/views/flowable/task/finished/index.vue')
          },

        ]
      },

      {
        path: '/about',
        meta: {
          title: '关于'
        },
        component: () => import('../views/about/s1.vue')
      },
      {
        path: '/user-center',
        meta: {
          title: '个人中心'
        },
        component: () => import('../views/userinfo/UserCenter.vue')
      },

    ]
  },
 
  {
    path: '/userinfo',
    meta: {
      title: '个人信息'
    },
    component: () => import('../views/userinfo/UserInfo.vue')
  },
]

const router = new VueRouter({
  routes
})

router.beforeEach(function (to, from, next) {
  if (to.path != '/document') {  // 流程在页面自定义title
    document.title = to.meta.title
  }
  next()
})


export default router
